package com.scujj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scujj.controller.UserController;
import com.scujj.mapper.SubcribeMapper;
import com.scujj.pojo.Result;
import com.scujj.pojo.Subcribe;
import com.scujj.pojo.User;
import com.scujj.service.SubcribeService;
import com.scujj.service.UserService;
import com.scujj.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

@Service
public class SubcribeServiceImpl extends ServiceImpl<SubcribeMapper, Subcribe> implements SubcribeService {

    @Autowired
    private SubcribeMapper subcribeMapper;

    @Autowired
    private UserService userService;

    @Override
    public User getUserWithSubscribeList(Long id) {
        User user= userService.getById(id);
        QueryWrapper<Subcribe> wrapper = new QueryWrapper<>();
        wrapper.eq("uid",user.getId());
        List<Subcribe> subscribeList= this.list(wrapper);
        List<User> userList=new LinkedList<>();
        subscribeList.forEach(subscribe -> {
            userList.add(userService.getById(subscribe.getSid()));
        });
        user.setSubcribeList(userList);
        return user;
    }

    @Override
    public User getUserWithFansList(long id) {
        User user= userService.getById(id);
        QueryWrapper<Subcribe> wrapper = new QueryWrapper<>();
        wrapper.eq("sid",user.getId());
        List<Subcribe> subscribeList= this.list(wrapper);
        List<User> userList=new LinkedList<>();
        subscribeList.forEach(subscribe -> {
            userList.add(userService.getById(subscribe.getUid()));
        });
        user.setFansList(userList);
        return user;
    }
}
